function delroles(id){
	layer.confirm("确定删除此课程吗?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		$.ajax({
			url : path+"/courses/course_delete",
			cache : false,
			type : 'post',
			dataType : 'html',
			data : {
				"id":id},
				error : function() {
					layer.alert("操作失败!");
				},
				success : function(message) {
					if(message == "200"){
						layer.msg('操作成功!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}else if(message == "500"){
						layer.alert("系统繁忙！");
					}else{
						layer.alert(message);
					}
				},complete: function(XMLHttpRequest, textStatus) {
					layer.close(layer_load_window);
				}
		});
	});
}

function reviewCourses(id){
	layer.confirm("是否通过审核?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		$.ajax({
			url : path+"/courses/course_review",
			cache : false,
			type : 'post',
			dataType : 'html',
			data : {
				"id":id},
				error : function() {
					layer.alert("操作失败!");
				},
				success : function(message) {
					if(message == "200"){
						layer.msg('操作成功,已审核。再次点击成为未审核状态!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}else if(message == "201"){
						layer.msg('操作成功,未审核。再次点击成为已审核状态!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}else if(message == "500"){
						layer.alert("系统繁忙！");
					}else if(message == "505"){
						layer.alert("已经审核，请勿重复点击!");
					}else{
						layer.alert(message);
					}
				},complete: function(XMLHttpRequest, textStatus) {
					layer.close(layer_load_window);
				}
		});
	});
}
function reviewSeries(id){
	layer.confirm("是否通过审核或未审核?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		$.ajax({
			url : path+"/coursesSeries/series_review",
			cache : false,
			type : 'post',
			dataType : 'html',
			data : {
				"id":id},
				error : function() {
					layer.alert("操作失败!");
				},
				success : function(message) {
					if(message == "200"){
						layer.msg('操作成功,已审核。再次点击成为未审核状态!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}else if(message == "201"){
						layer.msg('操作成功,未审核。再次点击成为已审核状态!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}
					else if(message == "500"){
						layer.alert("系统繁忙！");
					}else if(message == "505"){
						layer.alert("已经审核，请勿重复点击!");
					}else{
						layer.alert(message);
					}
				},complete: function(XMLHttpRequest, textStatus) {
					layer.close(layer_load_window);
				}
		});
	});
}

function reviewTopping(id){
	layer.confirm("是否置顶核或不置顶?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		$.ajax({
			url : path+"/coursesSeries/series_topping",
			cache : false,
			type : 'post',
			dataType : 'html',
			data : {
				"id":id},
				error : function() {
					layer.alert("操作失败!");
				},
				success : function(message) {
					if(message == "200"){
						layer.msg('操作成功,已置顶。再次点击成为不是置顶状态!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}else if(message == "201"){
						layer.msg('操作成功,不是置顶。再次点击成为置顶状态!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}
					else if(message == "500"){
						layer.alert("系统繁忙！");
					}else{
						layer.alert(message);
					}
				},complete: function(XMLHttpRequest, textStatus) {
					layer.close(layer_load_window);
				}
		});
	});
}

function isSchooling(id){
	layer.confirm("是否成为绝学?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		$.ajax({
			url : path+"/coursesSeries/isSchooling",
			cache : false,
			type : 'post',
			dataType : 'html',
			data : {
				"id":id},
				error : function() {
					layer.alert("操作失败!");
				},
				success : function(message) {
					if(message == "200"){
						layer.msg('操作成功,已是绝学。再次点击成为不是绝学!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}else if(message == "201"){
						layer.msg('操作成功,不是绝学。再次点击成为绝学!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}
					else if(message == "500"){
						layer.alert("系统繁忙！");
					}else{
						layer.alert(message);
					}
				},complete: function(XMLHttpRequest, textStatus) {
					layer.close(layer_load_window);
				}
		});
	});
}

function viewSeries(id){
	layer.open({
		type: 2,
		title: "查看系列课",
		scrollbar: true,
		maxmin: true,
		content: path+'/coursesSeries/coursesSeries_seriesLesson?id='+id,
		area: ['800px', '600px']
	});
}
function addSeriess(id){
	layer.open({
		type: 2,
		title: "添加系列课",
		scrollbar: true,
		maxmin: true,
		content: path+'/courses/add_to?id='+id,
		area: ['800px', '600px']
	});
}

function editrole(id){
	layer.open({
		type: 2,
		title: "修改课程",
		content: path+'/courses/modify_to?id='+id,
		area: ['700', '700px']
	});

}



var checkRoleNo = "true";
//当输入角色编码验证是否存在0存在  1 不存在 
function checkNo(roleNo){
	if(trim(roleNo)==""){
		alert("角色编码不能全为空格!!!");
		checkRoleNo = "false" ;
		return false;
	}	   
	if(roleNo!=""){
		$.ajax({
			url : path + '/role/role_checkNo',
			type : 'get',
			dataType : 'text',
			data : {"No":roleNo},
			error : function() {
			},
			success : function(result) {
				if(result=="200"){
					checkRoleNo = "true" ;	
				}else{
					layer.alert("角色编号已经存在！");
					checkRoleNo = "false" ;	
					return false;
				}
			}
		});	

	}
}
function trim(str){ 
	return str.replace(/(^\s*)|(\s*$)/g, "");
}
function update(){
	if(checkRoleNo=="false"){
		return;
	}
	var orgName =$("#coursetitle").val();
	var remark =$("#courseintroduction").val();
	var orgNon =$("#teacher").val();
	if(orgName.length==0 || trim(orgName).length == 0){
		layer.alert("课程标题不能为空！");
		window.orgAdmin.document.getElementById("coursetitle").focus();
		return;
	}
	if(remark.length==0 || trim(remark).length == 0){
		layer.alert("课程简介不能为空！");
		window.orgAdmin.document.getElementById("courseintroduction").focus();
		return;
	}
	if(orgName.length==0 || trim(orgName).length == 0){
		layer.alert("讲师不能为空！");
		window.orgAdmin.document.getElementById("teacher").focus();
		return;
	}
	//验证只包含字母或者汉字
	var pattern =/(^[\u4e00-\u9fa5A-Za-z0-9_-]*$)/;
	//验证不能为纯数字
	var patternNum=/^\d+$/;
	if (!pattern.test(orgName)) {
		layer.alert("请输入合法的课程标题！");
		return false;
	}
	if (patternNum.test(orgName)) {
		layer.alert("课程标题不能为纯数字！");
		return false;
	}

	if(orgNon.length==0 || trim(orgNon).length == 0){
		layer.alert("讲师不能为空");
		return false;
	}

//	var treeObj=$.fn.zTree.getZTreeObj("treeDemo");
//	var nodes=treeObj.getCheckedNodes(true);
//	v="";
//	for(var i=0;i<nodes.length;i++){
//	if(i==nodes.length-1){
//	v+=nodes[i].id;
//	}else{
//	v+=nodes[i].id + ",";
//	}

//	//获取选中节点的值
//	}
//	$("#ids").val(v);
//	var layer_load_window = layer.load(2); 
//	$("#form-role").ajaxSubmit({
//	dataType : 'html',
//	success: function(message){
//	if(message == "200"){
//	layer.msg('操作成功!',{icon:1,time:1000},function(){
//	/*                         var index = parent.layer.getFrameIndex(window.name);
//	parent.query_brand_form.submit();
//	parent.layer.close(index); */
//	parent.window.location.reload();
//	});
//	}else if(message == "500"){
//	layer.alert("系统繁忙！");
//	}else{
//	layer.alert(message);
//	}
//	},
//	error: function(){
//	layer.msg('操作失败!',{icon:5,time:1000});
//	},complete: function(XMLHttpRequest, textStatus) {
//	layer.close(layer_load_window);
//	}
//	});
}
function delSeries(id){
	layer.confirm("确定删除此课程吗?",function(){
		layer.closeAll('dialog');
		var layer_load_window = layer.load(2); 
		$.ajax({
			url : path+"/coursesSeries/series_delete",
			cache : false,
			type : 'post',
			dataType : 'html',
			data : {
				"id":id},
				error : function() {
					layer.alert("操作失败!");
				},
				success : function(message) {
					if(message == "200"){
						layer.msg('操作成功!',{icon:1,time:1000},function(){
							window.location.reload();
						});
					}else if(message == "500"){
						layer.alert("系统繁忙！");
					}else{
						layer.alert(message);
					}
				},complete: function(XMLHttpRequest, textStatus) {
					layer.close(layer_load_window);
				}
		});
	});
}